#include<iostream>
#include<vector>
#include<string>
using namespace std;
class Solution {
public:
    string longestPalindrome(string s) {
        int n=s.size();
        if(n==0)
        {
            return "";
        }
        int maxlen=0;
        int start =0;
        for(int i=0;i<n;i++)
        {
            int r=i,l=i;
            while(r<n&&l>=0&&s[r]==s[l])
            {
                if(r-l+1>maxlen)
                {
                    maxlen=r-l+1;
                    start=l;
                }
                l--;
                r++;
            }
            r=i+1;
            l=i;
            while(r<n&&l>=0&&s[r]==s[l])
            {
                if(r-l+1>maxlen)
                {
                    maxlen=r-l+1;
                    start=l;
                }
                l--;
                r++;
            }
        }
        return s.substr(start,maxlen);
    }
};
int main()
{
    Solution s;
    string test="cdadcdab";
    cout<<s.longestPalindrome(test)<<endl;
    return 0;
}